package org.duang.core;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.duang.common.exceptios.ServiceException;
import org.duang.config.InstanceFactory;
import org.duang.kit.ToolsKit;

/**
 * Duang框架报告
 * @author laotang
 */
 public class Reporter {
	
	/**
	 * 取出所有Action
	 * @return ActionInfo
	 */
	public static List<ActionInfo> getAllAction() {
		Map<String, Action> actionMap = InstanceFactory.getActionMapping();
		if(ToolsKit.isEmpty(actionMap)) {
			throw new ServiceException("actionMap is null!");
		}
		List<ActionInfo> allActionInfo = new ArrayList<ActionInfo>(actionMap.size());
		List<String> allActionKeys = new ArrayList<String>(actionMap.keySet());
		Collections.sort(allActionKeys);
		for(Iterator<String> it = allActionKeys.iterator(); it.hasNext(); ){
			String key = it.next();
			if(ToolsKit.isNotEmpty(key)){
				Action action = actionMap.get(key);
				String desc = action.getDescKey();
				int level = Integer.parseInt(action.getLevelKey());
				String order = action.getOrderKey();
				ActionInfo info = new ActionInfo(key, desc, level, order);
				allActionInfo.add(info);
			}
		}
		return allActionInfo;
	}

	
	public static class ActionInfo{
		private String url;
		private String desc;
		private int level;
		private String order;
		
		public ActionInfo(){
			
		}
		public ActionInfo(String url, String desc, int level, String order) {
			this.url = url;
			this.desc = desc;
			this.level = level;
			this.order = order;
		}
		public int getLevel() {
			return level;
		}
		public void setLevel(int level) {
			this.level = level;
		}
		public String getUrl() {
			return url;
		}
		public void setUrl(String url) {
			this.url = url;
		}
		public String getDesc() {
			return desc;
		}
		public void setDesc(String desc) {
			this.desc = desc;
		}
		public String getOrder() {
			return order;
		}
		public void setOrder(String order) {
			this.order = order;
		}
	}
}


